<?php

namespace apiend\models;

use common\base\Model;

/**
 * ContactForm is the model behind the contact form.
 */
class AvatarForm extends Model {

    public $avatar;

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['avatar'], 'required'],
        ];
    }

    /**
     * Sends an email to the specified email address using the information collected by this model.
     *
     * @param string $email the target email address
     * @return bool whether the email was sent
     */
    public function save() {
        if (!$this->validate()) {
            $this->dumpError('提交失败');
        }

        $user = $this->getUser();
        $user->avatar = $this->avatar;

        if (!$user->save()) {
            $this->dumpError('头像上传失败!', $user->getFirstErrors());
        }

        return $user;
    }

}
